<template>
  <div class="container billList">
    <h3 class="title" v-if="listData.length!=0">搜索结果</h3>
    <div class="nothing" v-if="listData.length==0">无相关流水单</div>
    <cube-scroll v-else>
      <!-- 流水单列表 -->
      <!-- 在此处添加图标 -->
      <ul class="bill-list">
        <li class="bill-item" v-for="(item, index) in listData" :key="index">
          <router-link class="billLink" :to="'/billdetail:'+item.order_sn	">
            {{item.order_sn }} {{item.user_name}}
            <span style="font-size:12px;">{{item.user_phone}}</span>
          </router-link>
          <div v-if="item.level == 1" class="subSqurt all">全额</div>
          <div v-if="item.level == 2" class="subSqurt first">首单</div>
          <div v-if="item.level == 3" class="subSqurt second">二单</div>
          <div v-if="item.level == 4" class="subSqurt three">三单</div>
          <div v-if="item.level == 5" class="subSqurt">积分</div>
          <!-- 
            0未知 1全额 2首单 3二单 4三单 5积分

          -->
        </li>
      </ul>
    </cube-scroll>
  </div>
</template>

<script>
import { Toast } from "mint-ui";
import  api from '../../assets/js/api'
export default {
  data() {
    return {
      listData: []
    };
  },
  methods: {
    searchBill(type = 1) {
      let loading = this.loading("搜索中", 10000);
      loading.show();
      this.axios
        .post("/api/butler/water_search", {
          search_word: this.searchContent,
          type: type
        })
        .then(response => {
          let res = response.data;
          loading.hide();
          if (res.code == 200) {
            loading.hide();
            this.listData = res.data;
          } else if (res.code == 250) {
            Toast({
              message: "登录过期，请重新登陆",
              position: "bottom",
              duration: 2000
            });
            this.$router.push("/login");
            return false;
          } else {
            loading.hide();
            Toast({
              message: res.msg,
              position: "bottom",
              duration: 2000
            });
          }
        })
        .catch(error => {
          Toast({
            message: "请求失败，请稍后重试",
            position: "bottom",
            duration: 2000
          });
        });
    }
  },
  props: ["searchContent"],
  created() {
    this.axios.defaults.baseURL = api
    let exp = /[0-9]/;
    if (exp.test(this.searchContent)) {
      this.searchBill(2);
    } else {
      this.searchBill(1);
    }
  }
};
</script>

<style lang="less" scoped>
.container {
  height: 100%;
  margin-top: 20px;
  .title {
    height: 50px;
    line-height: 50px;
    border-bottom: 1px solid rgba(204, 204, 204, 0.2999);
    font-size: 14px;
    color: #888;
    padding: 0 15px;
  }
  .bill-list {
    padding-bottom: 200px;
    .bill-item {
      padding: 0 0 0 15px;
      height: 50px;
      border-bottom: 1px solid rgba(204, 204, 204, 0.2999);
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      align-items: center;
      .subSqurt {
        width: 41px;
        height: 25px;
        background: rgba(234, 137, 137, 1);
        border-radius: 100px 0px 0px 100px;
        color: #fff;
        padding: 0 0 0 10px;
        font-size: 12px;
        line-height: 25px;
      }
      .subSqurt.all {
        background-color: #5f9bff;
      }
      .subSqurt.three {
        background-color: #a2a8fa;
      }
      .subSqurt.second {
        background-color: #f9a77f;
      }
      .subSqurt.first {
        background-color: #ff94b1;
      }
      .billLink {
        display: block;
        width: 100%;
        height: 100%;
        line-height: 50px;
      }
    }
  }
  .nothing {
    position: absolute;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 17px;
    color: #666;
    font-weight: bold;
  }
}
</style>



